package com.koron.ticket.work.logicticket.thirdticket.controller;

import com.koron.bean.base.Response;
import com.koron.bean.workflow.SubmitterParam;
import com.koron.bean.workflow.WorkflowUser;
import com.koron.common.core.business.workflow.util.TextUtil;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.common.core.util.FastJsonUtils;
import com.koron.ticket.work.logicticket.thirdticket.service.ThirdTicketService;
import com.koron.ticket.work.workticket.service.WorkTicketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags = "第三种工作票-插件")
@RestController
@RequestMapping("work/thirdticket/workflow")
public class ThirdTicketControllerWorkflow {

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @Autowired
    private ThirdTicketService thirdTicketService;

    @Autowired
    private WorkTicketService workticketservice;

    @ApiOperation("选择待许可人")
    @PostMapping("draftwrite/submitter")
    public Response<List<WorkflowUser>> submitter(@RequestBody SubmitterParam submitterParam) {
        //选择待许可人、工作票待终结人
        log.info("接收到的参数:" + FastJsonUtils.getBeanToJson(submitterParam));
        String formVariables = submitterParam.getFormVariables();
        Map<String, String> infoMap = TextUtil.toMapFromString(formVariables);
        List<WorkflowUser> list = workticketservice.getWorkflowUsers(submitterParam, null, 4);
//        List<WorkflowUser> list = ADOConnection.runTask(getCurrDs(), workticketservice, "getTicketApproverThisUnit", List.class, infoMap.get("id"), new PostUserQuery());//获取部门id
        log.info("返回到的人员:" + FastJsonUtils.getBeanToJson(list));
        return Response.success(list);
    }

    @PostMapping("/handler")
    public List<WorkflowUser> handler(SubmitterParam submitterParam) {
        return null;
    }
}
